<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>尺寸获取</title>
  <style>
    #box {
      margin: 50px auto;
      position: relative;
      width: 500px;
      height: 500px;
      border: 1px solid #000;
    }
    #div {
      position: absolute;
      left: 100px;
      top: 100px;
      width: 100px;
      height: 100px;
      /* padding: 5px; */
      /* border: 5px solid #000; */
      background: #f0f0f0;
    }
  </style>
</head>
<body>
  <div id="box">
    <div id="div">

    </div>
  </div>
  <script>
    let div = document.querySelector("#div")
    console.info(div.offsetWidth, div.offsetHeight); // 可视宽高 width（height） + padding + border
    console.info(div.offsetTop, div.offsetLeft); // 元素距离定位父级左上角的距离 。不会考虑padding和border

    console.info(div.clientWidth, div.clientHeight); // 可视宽高：width(height) + padding； 不包含border
    console.info(div.clientTop, div.clientLeft); // 左边框宽度/上边框宽度.就是border
  </script>
</body>
</html>